package com.cskaoyan.service.wx;

import com.cskaoyan.bean.bo.wjjBO.WXBrandDetailBO;
import com.cskaoyan.bean.bo.wjjBO.WXBrandListBO;
import com.cskaoyan.bean.marketBean.MarketBrand;
import com.cskaoyan.bean.vo.wjjVO.WXBrandListVO;
import com.cskaoyan.mapper.marketMapper.MarketBrandMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wjj
 * @date 2023-01-02 10:19
 * @describe
 */
@Service
public class WXBrandServiceImpl implements WXBrandService {

    @Autowired
    MarketBrandMapper brandMapper;

    @Override
    public MarketBrand selectMarkBrandById(WXBrandDetailBO brandDetailBO) {
        MarketBrand marketBrand = new MarketBrand();
        marketBrand.setId(brandDetailBO.getId());
        MarketBrand brand = brandMapper.selectMarketBrandByBrandId(marketBrand);
        return brand;
    }

    @Override
    public WXBrandListVO selectMarkBrandList(WXBrandListBO brandListBO) {
        PageHelper.startPage(brandListBO.getPage(), brandListBO.getLimit());
        //执行查询过程中拼接分页信息

        List<MarketBrand> brandList = brandMapper.selectMarkrtBrand();

        // 将查询结果作为有参构造方法的形参传入，可以获得PageInfo
        PageInfo<MarketBrand> pageInfo = new PageInfo<>(brandList);

        WXBrandListVO brandListVO = new WXBrandListVO();
        brandListVO.setTotal((int) pageInfo.getTotal());
        brandListVO.setPages(pageInfo.getPages());
        brandListVO.setLimit(brandListBO.getLimit());
        brandListVO.setPage(brandListBO.getPage());
        brandListVO.setList(brandList);
        return brandListVO;
    }
}
